#!/bin/sh

cd <%= node['gitlab']['gitlab-rails']['dir'] %>/working

exec 2>&1
<%= render("make_metrics_rundir.erb", cookbook: 'gitlab') %>
<%= render("mount_point_check.erb", cookbook: 'gitlab') %>
exec chpst -e /opt/gitlab/etc/gitlab-rails/env -P \
  -U <%= @options[:user] %>:<%= @options[:groupname] %> \
  -u <%= @options[:user] %>:<%= @options[:groupname] %> \
  /usr/bin/env \
    prometheus_multiproc_dir="${prometheus_run_dir}" \
    /opt/gitlab/embedded/service/gitlab-rails/bin/sidekiq-cluster \
      -e <%= node['gitlab']['gitlab-rails']['environment'] %> \
      -r /opt/gitlab/embedded/service/gitlab-rails \
      <% if node['gitlab']['sidekiq-cluster']['interval'] %>
      -i <%= node['gitlab']['sidekiq-cluster']['interval'] %> \
      <% end %>
      <% if node['gitlab']['sidekiq-cluster']['max_concurrency'] %>
      -m <%= node['gitlab']['sidekiq-cluster']['max_concurrency'] %> \
      <% end %>
      <% if node['gitlab']['sidekiq-cluster']['min_concurrency'] %>
      --min-concurrency <%= node['gitlab']['sidekiq-cluster']['min_concurrency'] %> \
      <% end %>
      <% if node['gitlab']['sidekiq-cluster']['experimental_queue_selector'] %>
      --experimental-queue-selector \
      <% end %>
      <% if node['gitlab']['sidekiq-cluster']['shutdown_timeout'] %>
      --timeout <%= node['gitlab']['sidekiq-cluster']['shutdown_timeout'] %> \
      <% end %>
      <% node['gitlab']['sidekiq-cluster']['queue_groups'].each do |queue| %>
        "<%= queue %>" \
      <% end %>
      <% if node['gitlab']['sidekiq-cluster']['negate'] %>
      --negate \
      <% end %>

# Do not remove this line; it prevents trouble with the trailing backslashes above.
